﻿using System;
using System.Collections.Generic;
using System.Text;

namespace daSyntaxAnalyser.SyntaxTree
{
    using daBase.Objects;

    public class ClassPropertyElement : InterfacePropertyElement
    {
        private PropertyOptionElement implements;
        private bool enddefault;

        public PropertyOptionElement Implements { get { return implements; } set { implements = value; } }
        public bool EndDefault { get { return enddefault; } set { enddefault = value; } }

        public ClassPropertyElement(TokenInfo Id, IndexIntervalElement IndexInterval, ITypeElement Type, ConstExpressionElement Index, PropertyOptionElement Read, PropertyOptionElement Write, PropertyOptionElement Stored, PropertyOptionElement Default, PropertyOptionElement Implements, bool EndDefault, List<TokenInfo> Comments)
            : base(Id, IndexInterval, Type, Index, Read, Write, Stored, Default, Comments)
        {
            implements = Implements;
            enddefault = EndDefault;
        }

        public override string ToString()
        {
            string result = string.Format("property {0}", id);
            if (indexinterval!=null) result += string.Format(" {0}", indexinterval);
            if (type != null) result += string.Format(" : {0}", type);
            if (index != null) result += string.Format("index {0}", index);
            if (read != null) result += string.Format(" {0}", read);
            if (write != null) result += string.Format(" {0}", write);
            if (stored != null) result += string.Format(" {0}", stored);
            if (_default != null) result += string.Format(" {0}", _default);
            if (implements != null) result += string.Format(" {0}", implements);
            if (enddefault) result += "; default";
            return string.Format("{0};", result);
        }

        protected override IEnumerator<ISyntaxTreeElement> CreateEnumerator()
        {
            IEnumerator<ISyntaxTreeElement> baseEnumerator = base.CreateEnumerator();
            while (baseEnumerator.MoveNext())
                yield return baseEnumerator.Current;
            if (implements != null)
                yield return implements;
        }
    }
}
